<?php

abstract class Component extends ObjLib\Object {
	public static $componentClassList;
	
	var $params = array (
		'URL',
		'title',
		'className'
	);
	
	abstract function render ($params = array());
	abstract function isRegisteredAction ($actionName);
	
	static function updateView () {
		global $dbh;
		
		$select = array ();
		foreach (static::$componentClassList as $class) {
			$select[] = "select id, url, title, {$dbh->quote ($class)} as `className` from `{$class}`";
		}
		
		$select = join ($select, ' union ');

		$dbh->exec ("create view Component as {$select}");
	}
	
	function save () {
		global $dbh;
		
		if (!$this->_saved) {
			$this->id = ObjLib\Object::genUniqueId ();
			
			$dbh->exec ('lock tables Component read');
			
			while (Component::exists ($this->id, 'Component')) {
				$this->id = ObjLib\Object::genUniqueId ();
			}
			
			$ret = parent::save ();
			
			$dbh->exec ('unlock tables Component read');
			return $ret;
		}
		else {
			return parent::save ();
		}
	}
}

?>